<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH 数据资产</title>
    <meta name="keywords" content="ZDH 数据资产">
    <meta name="description" content="ZDH 数据资产">

    <link rel="shortcut icon" href="img/favicon.ico">
    <link rel="stylesheet" type="text/css" href="js/layui/lib/layui-v2.5.5/css/layui.css"/>
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">

    <style type="text/css">
        .btn_page {
        }
        .label_active{
            background-color: #18a689;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
<!--                        <h2>-->
<!--                                为您找到相关结果约total_size个： <span class="text-navy">“数据资产”</span>-->
<!--                        </h2>-->
                        <div class="search-form">
                            <form method="get" id="etl_task_form">
                                <div class="input-group  col-sm-2">
                                    <select id="product_code" name="product_code"
                                            data-placeholder="产品code...."
                                            class="chosen-select form-control m-b" >
                                    </select>
                                </div>
                                <div class="input-group">
                                    <input type="text" placeholder="数据资产" name="issue_context" class="form-control input-lg">
                                    <div class="input-group-btn">
                                        <button class="btn btn-lg btn-primary" type="button" οnsubmit='return false' id="search">
                                            搜索
                                        </button>
                                    </div>
                                </div>
                            </form>
                            <div class="col-sm-12" id="label_div">

                            </div>
                            <br/>
                            <br/>
                        </div>
                        <br/>
                        <br/>
                        <br/>
                        <br/>
                        <br/>
                        <div id="data_div">

                        </div>


                        <div class="text-center">
                            <div id="itemPage">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="js/zdh_common.js"></script>
    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <script src="js/plugins/chosen/chosen.jquery.js"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>

    <script type="text/javascript" src="js/layui/lib/layui-v2.5.5/layui.js"></script>
    <!-- layer javascript -->
    <script src="js/plugins/layer/layer.min.js"></script>

    <script src="js/admin/dim_product_common.js"></script>

    <script>

        //加载标签
        function load_label() {
            var label_template = " <label>label_name</label>&nbsp&nbsp&nbsp&nbsp\n";
            var a_template = "<button type=\"button\" class=\"btn btn-outline btn-default\" enum_value=\"enum_value_replace\">enum_context</button>\n";
            var line_template = "                                <br/>\n";
            $.ajax({
                type: 'POST',
                async: false,
                url: server_context+"/data_ware_house_label",
                dataType: 'json',
                data: '',
                //成功返回
                success: function (data) {
                    $('#label_div').html("");
                    if(data.result.length>0){
                        for(var i=0;i<data.result.length;i++){
                            var dt = data.result[i];
                            var label_html = label_template.replace("label_name", dt.enum_context);

                            if(dt.enum_json_object.length>0){
                               for (var j=0;j<dt.enum_json_object.length;j++){
                                   label_html=label_html+a_template.replace("enum_value_replace",dt.enum_json_object[j].enum_value).replace("enum_context", dt.enum_json_object[j].enum_value_context);
                               }
                            }
                            label_html = label_html+line_template;
                            $('#label_div').append(label_html);
                        }
                    }

                    $('#label_div button').click(function () {
                        if($(this).hasClass("btn-default")){
                            $(this).removeClass("btn-default");
                            $(this).addClass("btn-info")
                        }else{
                            $(this).removeClass("btn-info");
                            $(this).addClass("btn-default");
                        }
                    });
                },
                //处理完成
                complete: function () {
                    console.info("etl_task_complete")
                },
                //报错
                error: function (data) {
                    console.info("etl_task_error: " + data.responseText);
                }
            });
        }

        function openTabPage(url, title) {
            var wpd = $(window.parent.document);
            var mainContent = wpd.find('.J_mainContent');
            var thisIframe = mainContent.find("iframe[data-id='" + url + "']");
            var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ');
            pageTabs.find(".J_menuTab.active").removeClass("active");
            mainContent.find("iframe").css("display", "none");
            if (thisIframe.length > 0) {	// 选项卡已打开
                thisIframe.css("display", "inline");
                pageTabs.find(".J_menuTab[data-id='" + url + "']").addClass("active");
            } else {
                var menuItem = wpd.find("a.J_menuItem[href='" + url + "']");
                var dataIndex = title == undefined ? menuItem.attr("data-index") : '9999';
                var _title = title == undefined ? menuItem.find('.nav-label').text() : title;
                var iframe = '<iframe class="J_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
                    + '" seamless="" style="display: inline;"></iframe>';
                pageTabs.append(
                    ' <a href="javascript:;" class="J_menuTab active" data-id="' + url + '">' + _title + ' <i class="fa fa-times-circle"></i></a>');
                mainContent.append(iframe);
                //显示loading提示
                var loading = top.layer.load();
                mainContent.find('iframe:visible').load(function () {
                    //iframe加载完成后隐藏loading提示
                    top.layer.close(loading);
                });
            }

        }

        var data_params = "";
        var label_params = new Array();
        $(document).ready(function () {
            $('#search').click(function () {
                data_params = $('#etl_task_form').serialize();
                label_params = new Array();
                $('#label_div .btn-info').each(function ( index,element){
                    label_params.push($(this).attr('enum_value'));
                });
                //load_data(1);
                load_data2(1, 5);
            });

            // $('.btn_page').click(function () {
            //     var currentPage = $(this).attr('value');
            //     $('.btn_page').removeClass("active");
            //     $(this).addClass("active");
            //
            // });
            load_label();
            $('#search').click();
        });

        var template =
        "<div class='row'>\n"+
        "<div class='col-sm-11'>\n"+
        "                            <div class=\"search-result\" style='margin-top: 20px'>\n" +
        "                                <h3><a href=\"javascript:void(0)\" data_id='table_id' data_id_context='data_context'>table_name</a></h3>\n" +
        "                                <p>\n" +
        "                                    data_context" +
        "                                </p>" +
        "                            </div>\n" +
        "</div>\n"+
        "<div class='col-sm-1' style='margin-top: 25px;text-align: right'><button class=\"btn btn-primary btn_apply\" type=\"button\" data_id='table_id'>申请</button> </div>\n"+
            "                            <div class=\"hr-line-dashed\"></div>\n"+
        "</div>\n"+
        "</div>"
        ;



    </script>

    <script type="text/javascript">

        function apply_add_index(id){
            parent.layer.open({
                type: 2,
                title: '申请数据',
                shadeClose: false,
                resize: true,
                fixed: false,
                maxmin: true,
                shade: 0.1,
                area : ['45%', '60%'],
                //area: ['450px', '500px'],
                content: server_context+"/data_apply_add_index?id="+id, //iframe的url
                end : function () {
                    console.info("弹框结束");
                }
            });
        }
        // 加载laypage模块
        function load_data2(currentPage, page_size){

            $.ajax({
                type: 'POST',
                async: false,
                url: server_context+"/data_ware_house_list6?current_page="+currentPage+"&"+data_params+"&label_params="+label_params+"&page_size="+page_size,
                dataType: 'json',
                data: '',
                //成功返回
                success: function (data) {
                    if(data.code != "200"){
                        layer.msg(data.msg);
                        return ;
                    }
                    layui.use("laypage",function() {
                        var laypage = layui.laypage;

                        // 加载laypage实例
                        laypage.render({
                            elem: "itemPage", // elem绑定的是容器的id属性值，不需要加#
                            count: data.result.total_size, // 总数量，一般是从服务器获取
                            limit: 5, // 每页显示的数量
                            limits: [5, 10, 20, 30,100], // 每页条数选项
                            layout: ['prev', 'page', 'next', 'limit', 'count', 'skip'], // 自定义排版
                            groups: 10, // 连续显示的页码数
                            jump: function (obj) {
                                load_data3(obj.curr, obj.limit)
                            }
                        });
                    });

                    $('#data_div').html("");

                    if( data.result.list.length>0){

                        for(var i=0;i < data.result.list.length;i++){
                            var tmp = template.replace("table_name",  data.result.list[i].data_sources_table_name_input);
                            tmp = tmp.replaceAll("table_id", data.result.list[i].id);
                            tmp = tmp.replaceAll("data_context",  data.result.list[i].issue_context);
                            $('#data_div').append(tmp);
                        }

                        $(".search-result a").click(function () {
                            openTabPage(server_context+"/data_ware_house_detail_index.html?id=" + $(this).attr("data_id"), "表信息:"+$(this).attr("data_id_context"))
                        });

                        $(".btn_apply").click(function () {
                            var id= $(this).attr('data_id');

                            apply_add_index(id);

                            // layer.confirm('申请数据', {
                            //     btn: ['确定','取消'] //按钮
                            // }, function(index){
                            //     $.ajax({
                            //         url: server_context+"/data_apply_add",
                            //         data: "issue_id=" + id,
                            //         type: "post",
                            //         async:false,
                            //         dataType: "json",
                            //         success: function (data) {
                            //             console.info(data.msg);
                            //             layer.msg(data.msg)
                            //         },
                            //         error: function (data) {
                            //             console.info("error: " + data.msg);
                            //         }
                            //
                            //     });
                            // }, function(){
                            //
                            // });
                        });
                    }

                },
                //处理完成
                complete: function () {
                    console.info("etl_task_complete")
                },
                //报错
                error: function (data) {
                    console.info("etl_task_error: " + data.responseText);
                }
            });
        }

        function load_data3(currentPage, page_size){

            $.ajax({
                type: 'POST',
                async: false,
                url: server_context+"/data_ware_house_list6?current_page="+currentPage+"&"+data_params+"&label_params="+label_params+"&page_size="+page_size,
                dataType: 'json',
                data: '',
                //成功返回
                success: function (data) {
                    if(data.code != "200"){
                        layer.msg(data.msg);
                        return ;
                    }
                    $('#data_div').html("");
                    if(data.result.list.length>0){
                        for(var i=0;i <data.result.list.length;i++){
                            var tmp = template.replace("table_name", data.result.list[i].data_sources_table_name_input);
                            tmp = tmp.replaceAll("table_id",data.result.list[i].id);
                            tmp = tmp.replaceAll("data_context", data.result.list[i].issue_context);
                            $('#data_div').append(tmp);
                        }

                        $(".search-result a").click(function () {
                            openTabPage(server_context+"/data_ware_house_detail_index.html?id=" + $(this).attr("data_id"), "表信息:"+$(this).attr("data_id_context"))
                        });

                        $(".btn_apply").click(function () {
                            var id= $(this).attr('data_id');

                            apply_add_index(id);

                            //alert();
                            // layer.confirm('申请数据', {
                            //     btn: ['确定','取消'] //按钮
                            // }, function(index){
                            //     $.ajax({
                            //         url: server_context+"/data_apply_add",
                            //         data: "issue_id=" + id,
                            //         type: "post",
                            //         async:false,
                            //         dataType: "json",
                            //         success: function (data) {
                            //             console.info(data.msg);
                            //             layer.msg(data.msg)
                            //         },
                            //         error: function (data) {
                            //             console.info("error: " + data.msg);
                            //         }
                            //
                            //     });
                            // }, function(){
                            //
                            // });

                        });
                    }

                },
                //处理完成
                complete: function () {
                    console.info("etl_task_complete")
                },
                //报错
                error: function (data) {
                    console.info("etl_task_error: " + data.responseText);
                }
            });
        }
    </script>

</body>

</html>
